﻿using CheckIn.UserInfoHost.Infrastructures;
using JMS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheckIn.UserInfoHost.AutoRuns
{
    public class AutoUpdateWechatToken : IScheduleTask
    {
        public double[] Timers => null;

        public int Interval => 10000;

        public int RetryInterval => 10000;

        DateTime _lastUpdateTime = DateTime.Now;
        private readonly WechatService _wechatService;

        public AutoUpdateWechatToken(WechatService wechatService)
        {
            _wechatService = wechatService;
        }

        public void Run()
        {
            if ((DateTime.Now - _lastUpdateTime).TotalMinutes >= 3)
            {
                _wechatService.GetToken().GetAwaiter().GetResult();
                _lastUpdateTime = DateTime.Now;
            }
        }
    }
}
